﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace Twinkle.Tweak
{
    public class TUser : Krile.Kernel.Data.User
    {
        public override string ParentServiceId
        {
            get { return Define.ServiceId; }
        }

        public static string GetUserIDByNode(XElement uNode)
        {
            if (uNode == null || uNode.Element("screen_name") == null)
                return null;
            return uNode.Element("screen_name").ParseString();
        }

        public static TUser CreateByNode(XElement uNode)
        {
            if (uNode == null || uNode.Element("screen_name") == null)
                return null;
            return new TUser(uNode);
        }

        public TUser() : base() { }

        private TUser(XElement uNode)
        {
            this.NumericId = uNode.Element("id").ParseLong();

            this.Id = uNode.Element("screen_name").ParseString();

            this.Name = uNode.Element("name").ParseString();
            //location
            //description
            this.IconUri = uNode.Element("profile_image_url").ParseUri();
            //this.ProfileUri = uNode.Element("url").ParseUri();
            this.ProfileUri = new Uri("http://twitter.com/" + this.Id);
            this.Protected = uNode.Element("protected").ParseBool(true);
            //friends_count int
            //followes_count int
            //created_at dt
            //favourites_count long
            //utc_offset utc
            //time_zone string
            //statuses_count long
            //notifications bool
            //verified bool
            this.Following = uNode.Element("following").ParseBool();

            //profile_background_image_url
            //prifile_background_tile
            //profile_background_color
            //profile_text_color
            //profile_link_color
            //profile_sidebar_fill_color
            //profile_sidebar_fill_color

        }

        public long NumericId { get; private set; }

        public override int GetHashCode()
        {
            return (int)this.NumericId;
        }

        public override string Name
        {
            get
            {
                if (Kernel.Config.StatusDesign.ShowIDAlternative)
                    return "@" + base.Id + "/" + base.Name;
                else
                    return base.Name;
            }
            set
            {
                base.Name = value;
            }
        }
    }
}
